package com.arron.algorithm.leetcodetop100.二分查找;


import org.omg.CORBA.MARSHAL;

/**
 * 153.寻找旋转排序数组中的最小值
 */
public class 寻找旋转排序数组中的最小值 {


    public int findMin(int[] nums) {

        if (nums.length == 1){
            return nums[0];
        }
        //找到旋转点
        int left = 0;
        int right = nums.length-1;
        int min = Integer.MAX_VALUE;
        while (left<= right){
            int mid = left+ (right-left)/2;
            min =Math.min(min,Math.min(nums[right], Math.min(nums[left],nums[mid])));
            if (nums[left] < nums[mid]){

                min = Math.min(nums[left],min);
                left = mid +1;
                right--;
            }else {
              left++;
              right = mid-1;
            }

        }

        return min;

    }

}
